package com.deyuans.service.Impl;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deyuans.domian.User;
import com.deyuans.dto.RiskDto;
import com.deyuans.mapper.UserMapper;
import com.deyuans.service.UserService;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public boolean CreditRequest(RiskDto riskDto) {

        //判断是否为空
        if (riskDto==null){
            return false;
        }

//        使用三方接口提供的方法进行查询操作


        return false;
    }

    public boolean RequestDemo(User user){
        Gson gson = new Gson();
//        String path = "http://xinshujudgestructv4.api.bdymkt.com/ws/ent/punishmentNew";
//        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);
//        request.setCredentials("您的 access key", "您的 secret key");
//        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");
//        request.addQueryParameter("sign", "");
//        request.addQueryParameter("entityName", "");
//        request.addQueryParameter("idCard", "");
//        request.addQueryParameter("punishType", "");
//        request.addQueryParameter("needBranch", "");
//        ApiExplorerClient client = new ApiExplorerClient(new AppSigner());
        //当查询到该用户的是有风险情况就会获取到内容
        //{
        //    "orderNo": "202001031351208830003",
        //    "data": [
        //        {
        //            "regNo": "01335",
        //            "decideOrg": "上海市工商行政管理局",
        //            "partiesName": "大林**有限公司",
        //            "criminalType": "不按照规定办理注销登记",
        //            "punishContent": "吊销营业执照",
        //            "partyType": 1,
        //            "idNumber": "",
        //            "decideBasis": "",
        //            "oldPartiesName": "",
        //            "decideDate": "2011-06-28",
        //            "hitType": "当事人",
        //            "areaName": "上海市长宁区",
        //            "legalPerson": "",
        //            "decideNo": "沪工商案处字〔2011〕第000201110037号",
        //            "punishType": "工商行政处罚",
        //            "publishOrg": ""
        //        }
        //    ],
        //    "rc": "0000",
        //    "msg": "查询成功"
        //}

        //没涉及风向则 data={}
        //存在风险的内容

//        try {
//            ApiExplorerResponse response = client.sendRequest(request);
//            // 返回结果格式为Json字符串
//            System.out.println(response.getResult());
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        String json="{'data':{'regNo':'01335'}";
        //不存在风险的
        String json2="{'data':{}";
        Map map = gson.fromJson(json2, Map.class);
        if (map.get("data")!=null){
            return false;
        }

        return true;
    }
}
